﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aphysoft.Vate
{
    internal sealed class TransformationDebugger : IDebugCommandHandler
    {
        #region Constructor

        internal TransformationDebugger()
        {
            Debug.RegisterCommandHandler("transformation", this);
            Debug.Write("TransformationDebugger Initialized");
        }

        #endregion

        #region IDebugCommandHandler Members

        public bool Call(string command, string parameter)
        {
            if (command == "transformation")
            {
                #region help
                if (parameter.ToLower() == "help")
                {
                    Debug.Write("Transformation Manager");
                    Debug.Write("list - lists all transformation in transformation list");
                    Debug.Write("info <transformation no> - get transformation informations");
                }
                #endregion
                #region lists tranformations in this manager: transformation list
                else if (parameter.ToLower() == "list")
                {
                    Debug.Write(StringHelper.Create("Transformation available: ", Transformation.TransformationsList.Count));
                    int i = 0;
                    foreach (Transformation entry in Transformation.TransformationsList)
                    {
                        i++;
                        Debug.Write(StringHelper.Create(i, ". ", entry.Position));
                    }
                }
                #endregion
                #region Transformation informations: transformation info <transformation no>
                else if (parameter.ToLower().StartsWith("info "))
                {
                    string actcn = parameter.Substring(5).Trim();

                    int cn;
                    if (int.TryParse(actcn, out cn))
                    {
                        if (cn > 0 && cn <= Transformation.TransformationsList.Count)
                        {
                            cn--;
                            Transformation transformation = Transformation.TransformationsList[cn];

                            Debug.Write(StringHelper.Create("Position: ", transformation.Position));
                            Debug.Write(StringHelper.Create(" Forward: ", transformation.Forward));
                            Debug.Write(StringHelper.Create("      Up: ", transformation.Up));
                            Debug.Write(StringHelper.Create("   Right: ", transformation.Right));
                            Debug.Write(StringHelper.Create("   Scale: ", transformation.Scales));                            
                        }
                        else
                        {
                            Debug.Write("transformation no not found.");
                        }
                    }
                    else
                    {
                        Debug.Write("transformation no invalid.");
                        return false;
                    }
                }
                #endregion
                else
                {
                    Debug.Write("Transformation Manager, see transformation help for more information.");
                }
                return true;
            }
            return false;
        }

        public string Description(string command)
        {
            if (command == "transformation")
            {
                return "Transformation manager";
            }

            return null;
        }

        #endregion
    }
}
